package com.evil.common.account.enums;

import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 企业类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum PlatformTypeEnum {

    /**
     * 企业类型
     */
    ENTERPRISE(0, "企业"),
    ADMIN_PLATFORM(1, "平台"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<PlatformTypeEnum> isExistById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static PlatformTypeEnum findById(Integer id) {
        return PlatformTypeEnum.isExistById(id).orElseThrow(PlatformTypeEnum::getBusinessException);
    }

    public static BusinessException getBusinessException() {
        return new BusinessException(RCodeEnum.ERROR_PARAMETER, "企业类型参数错误");
    }
}
